<?php
/**
 * Copyright (c) 2007, PORTALIER Julien
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright    Copyright (c) 2007, Julien PORTALIER
 * @link         http://feather-cm.googlecode.com/
 * @license      http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

class RssReader
{
	function __construct($url, $cache='+20 minutes')
	{
		$this->url = $url;
		
		# cached?
		$xml_cache = 'rss.'.md5($url);
		$xml_str   = cache($xml_cache, null, $cache);
		if (!$xml_str)
		{
			# downloads
			$xml_str = file_get_contents($url);
			cache($xml_cache, $xml_str);
		}
		
		# parses
		$this->xml = simplexml_load_string($xml_str);
	}
	
	function getItems($limit=null)
	{
		$items = $this->xml->xpath('//rss/channel/item');
		if ($limit)
			$items = array_slice($items, 0, $limit);
		return $items;
	}
}
?>